﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Rhino.Mocks;

namespace Rhino.AutoMocker
{
    public class Hello
    {
    }

    public interface IRepository<T> where T : class
    {
        void Save();
    }

    public class HelloRepoImpl : IRepository<Hello>
    {
        #region IRepository<Hello> Members

        public void Save()
        {
            Console.WriteLine("Save");
        }

        #endregion
    }

    public class Foo
    {
        public IDictionary<string, string> dict { get; set; }
        public IRepository<Hello> HelloRepo { get; set; }
        public void Bar()
        {
            HelloRepo.Save();
        }
    }

    [TestClass]
    public class AutoMockerTest
    {
        [TestMethod]
        public void AutoMockTest_For_Generic_Repo()
        {
            // Arrange
            AutoMocker autoMocking = new AutoMocker();
            autoMocking.IsDebugEnabled = false;
            Foo foo = autoMocking.Create<Foo>();

            // Act
            foo.Bar();

            // Assert
            foo.HelloRepo.AssertWasCalled(x => x.Save());
            Assert.IsNull(foo.dict);
        }

        [TestMethod]
        public void AutoMockTest_For_Generic_Repo_With_ConcreteImplementation()
        {
            // Arrange
            AutoMocker autoMocking = new AutoMocker();
            autoMocking.AddComponent<IRepository<Hello>>(new HelloRepoImpl());
            Foo foo = autoMocking.Create<Foo>();

            // Act
            foo.Bar();

            // Assert
            //foo.HelloRepo.AssertWasCalled(x => x.Save());
        }
    }
}
